from lxml import etree
import requests
import mysql
import pymysql
import time
import re
def sheep():
    time.sleep(1)
# def pacong(cityName,citylink):
url="https://www.jianzhimao.com/ctrlcity/changeCity.html"
headers={
        'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44'
    }
rep=requests.get(url=url,headers=headers)
cityHtml=rep.text
tree=etree.HTML(cityHtml)
cityName=tree.xpath('//ul[@class="city_table"]/li/a/text()')
citylink=tree.xpath('//ul[@class="city_table"]/li/a/@href')
# print(type(citylink))
# print(citylink)
# print(cityName)

def nachuareahtml():
    bd = pymysql.connect(host="localhost", user="root", password="zs233", database="py_sql_jianzhimao")
    cursor = bd.cursor()
    sql = "SELECT * FROM areainfo"
    cursor.execute(sql)
    allarealink = cursor.fetchall()
    # print(allarealink)
    bd.close()
    return allarealink

def area_link():
    global allarealink
    cutarealink = []
    for i in nachuareahtml():
        allarealink = i[-1]
        cutarealink.append(allarealink)
        # print(allarealink)
    return cutarealink

def job_title():
    bd = pymysql.connect(host="localhost", user="root", password="zs233", database="py_sql_jianzhimao")
    cursor1 = bd.cursor()
    sql = "SELECT job_title_href FROM city_job_title"
    cursor1.execute(sql)
    all_job_href = cursor1.fetchall()
    # print(all_job_href)
    bd.close()
    return all_job_href

        # print(job_page)
